package com.mobimagic.lockscreen.view;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewStub;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.mobimagic.lockscreen.AppEnv;
import com.mobimagic.lockscreen.Charge;
import com.mobimagic.lockscreen.Charge.ChargingType;
import com.mobimagic.lockscreen.Charge.ChargingValueType;
import com.mobimagic.lockscreen.MobileChargingHelper;
import com.mobimagic.lockscreen.R;
import com.mobimagic.lockscreen.activity.MobileChargingActivity;
import com.mobimagic.lockscreen.report.StatKey;
import com.mobimagic.lockscreen.report.Statistician2;
import com.mobimagic.lockscreen.sdk.ILockScreenAd;
import com.mobimagic.lockscreen.sdk.ILockScreenBooster;
import com.mobimagic.lockscreen.sdk.ILockScreenCommon;
import com.mobimagic.lockscreen.sdk.ILockScreenHelper;
import com.mobimagic.lockscreen.sdk.LockScreenSDK;
import com.mobimagic.lockscreen.util.AppUtils;
import com.mobimagic.lockscreen.util.NetworkUtils;
import com.mobimagic.lockscreen.view.MobileChargingScrollView.ScrollInfo;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.AnimatorListenerAdapter;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.animation.ValueAnimator;
import com.nineoldandroids.animation.ValueAnimator.AnimatorUpdateListener;
import com.nineoldandroids.view.ViewHelper;
import com.qihoo360.common.utils.Utils;

public class MobileChargingView extends FrameLayout implements OnClickListener,
        MobileChargingScrollView.MobileScrollAdapter {
    private static final boolean TEST = false;
    public static final boolean TEST_MODE = false;
    public static final boolean DEBUG = AppEnv.bAppdebug;
    public static final String TAG = "MobileChargingView";

    private MobileChargingBGView mobileChargingBGView;
    private BubbleView mBubbleView;
    private MobileChargingScrollView mobileChargingScrollView;
    private Charge charge;
    private Context mContext;
    private MagicLayout boosterView;
    private SlideTextView slideTextView;
    private LayoutInflater layoutInflater;
    //    private List<NativePromoAd> registedVKNativeAd = new ArrayList<NativePromoAd>();
    //    private AdvData needReportShowAdvData;
    private OnChargingViewSlideListener slideListener;

    float startX, offsetX, startY;
    int width, height;

    private List<String> fbIds = new ArrayList<String>();
    private FrameLayout switchMenu;
    private PopupWindow popupWindow;
    private FadeView mFadeView;
    private List<Integer> report = new ArrayList<Integer>();
    private AvailableTimeView availTimeView;
    private boolean hasStop;
    private boolean theFirstShowCharge;
    private TopFadeView topFadeView;
    private float adCardHeight;

    private ActivityStatus activityStatus;
    private boolean isSlidAnimating = false;
    private boolean isReportShowHead;
    private BoostResultCardView boostResultView;
    private MobileChargeColorHelper mColorHelper;
    private ObjectAnimator objectAnimator;
    private List<String> boosterListPkg;
    private Handler mHandler;
    private Runnable runable;
    private Activity mActivity;
    private ILockScreenHelper mLockScreenHelper;
    private ILockScreenBooster mLockScreenBooster;
    private ILockScreenCommon mLockScreenCommon;
    private ILockScreenAd mLockScreenAd;

    public enum ActivityStatus {
        Create, Start, Resume, Pause, Stop, Destory;
    }

    public enum CardType {
        Null(0, 0), Notify(0, 0), AD(StatKey.STATISTIC_MOBILE_CHARGING_AD_CARD_SHOW_HEAD,
                StatKey.STATISTIC_MOBILE_CHARGING_AD_CARD_SHOW_ALL), BoosterResult(
                StatKey.STATISTIC_MOBILE_CHARGING_BOOSTER_CARD_SHOW_HEAD, -1), UseTime(
                StatKey.STATISTIC_MOBILE_CHARGING_USE_TIME_SHOW_HEAD, -1), ChargeTip(-1, 0);

        private int showHead, showAll;

        private CardType(int showHead, int showAll) {
            this.showHead = showHead;
            this.showAll = showAll;
        }
    }

    public MobileChargingView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mHandler = new Handler();
        mActivity = (Activity) context;
        mContext = LockScreenSDK.getInstance().getContext();
        layoutInflater = LayoutInflater.from(getContext());
        charge = MobileChargingHelper.getInstance().charge;
        mColorHelper = MobileChargingHelper.getInstance().getColorHelper();
        mLockScreenHelper = LockScreenSDK.getInstance().getLockScreenHelper();
        mLockScreenAd = LockScreenSDK.getInstance().getLockScreenAd();
        mLockScreenBooster = LockScreenSDK.getInstance().getLockScreenBooster();
        mLockScreenCommon = LockScreenSDK.getInstance().getLockScreenCommon();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mobileChargingBGView = (MobileChargingBGView) findViewById(R.id.mobile_charging_bg_view);
        mBubbleView = (BubbleView) findViewById(R.id.bubbles);
        topFadeView = (TopFadeView) findViewById(R.id.top_fadeview);
        mobileChargingBGView.setTopFadeView(topFadeView);
        mBubbleView.setTopFadeView(topFadeView);

        mobileChargingScrollView = (MobileChargingScrollView) findViewById(R.id.super_scroll_view);
        mobileChargingScrollView.setMobileScrollAdapter(this);
        switchMenu = (FrameLayout) findViewById(R.id.switch_menu);
        mFadeView = (FadeView) findViewById(R.id.fadeview);
        mFadeView.setVisibility(View.INVISIBLE);

        switchMenu.setOnClickListener(this);
        slideTextView = (SlideTextView) findViewById(R.id.slid_to_unlock);
        slideTextView.setText(LockScreenSDK.getInstance().getString(R.string.slide_unlock) + ">");

        if (TEST) {
            testChargingValue();
        }
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        mColorHelper.addObserver(mobileChargingBGView);
        mColorHelper.addObserver(mFadeView);
        mColorHelper.addObserver(slideTextView);
    }

    private void testChargingValue() {
        LinearLayout linearLayout = new LinearLayout(getContext());
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        addView(linearLayout);

        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
        final Button btn = new Button(getContext());
        btn.setText("-");
        final Button add = new Button(getContext());
        add.setText("+");
        linearLayout.addView(btn, layoutParams);
        linearLayout.addView(add, layoutParams);

        final Button disconnect = new Button(getContext());
        disconnect.setText("disconnect");
        linearLayout.addView(disconnect, layoutParams);

        final Button connect = new Button(getContext());
        connect.setText("connect");
        linearLayout.addView(connect, layoutParams);

        final Button memery60 = new Button(getContext());
        memery60.setText("内存上限改为60");
        linearLayout.addView(memery60, layoutParams);

        final Button screenOn = new Button(getContext());
        screenOn.setText("screenOn");
        linearLayout.addView(screenOn, layoutParams);

        final Button screenOff = new Button(getContext());
        screenOff.setText("screenOff");
        linearLayout.addView(screenOff, layoutParams);

        final Button memery5 = new Button(getContext());
        memery5.setText("内存上限为5");
        linearLayout.addView(memery5, layoutParams);

        final Button memery85 = new Button(getContext());
        memery85.setText("内存上限为85");
        linearLayout.addView(memery85, layoutParams);

        final Button protected5 = new Button(getContext());
        protected5.setText("保护期时间变为5秒");
        linearLayout.addView(protected5, layoutParams);

        final Button protected10 = new Button(getContext());
        protected10.setText("保护期时间变为10分钟");
        linearLayout.addView(protected10, layoutParams);

        final Button refresh = new Button(getContext());
        refresh.setText("刷新");
        linearLayout.addView(refresh, layoutParams);

        final OnClickListener onClickListener = new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (btn == v) {
                    float value = charge.getChargingValue() - 0.1f;
                    boolean real = value >= 0 && value <= 1;
                    if (!real) {
                        value = 0.5f;
                    }
                    charge.setChargingValueAndCalc(value, real);
                    setChargingViews();
                } else if (add == v) {
                    float value = charge.getChargingValue() + 0.1f;
                    boolean real = value >= 0 && value <= 1;
                    if (!real) {
                        value = 0.5f;
                    }
                    charge.setChargingValueAndCalc(value, real);
                    setChargingViews();

                } else if (disconnect == v) {
                    Intent intent = new Intent(Intent.ACTION_POWER_DISCONNECTED);
                    onReceiver(intent);
                    //                    TextView tv = new TextView(mContext);
                    //                    tv.setText("hellokitty");
                    //                    addCardView(tv, CardType.Notify);
                } else if (connect == v) {

                    Intent intent = new Intent(Intent.ACTION_POWER_CONNECTED);
                    onReceiver(intent);

                } else if (memery60 == v) {
                } else if (screenOff == v) {
                    onScreenOff();

                } else if (screenOn == v) {
                    onScreenOn();
                } else if (memery5 == v) {
                } else if (memery85 == v) {
                } else if (protected5 == v) {
                } else if (protected10 == v) {
                } else if (refresh == v) {
                    MobileChargingHelper.getInstance().getColorHelper()
                            .change(MobileChargingActivity.EXTRA_FROM_ONLY_REFRESH, true);
                }

            }
        };
        btn.setOnClickListener(onClickListener);
        add.setOnClickListener(onClickListener);
        disconnect.setOnClickListener(onClickListener);
        connect.setOnClickListener(onClickListener);
        memery60.setOnClickListener(onClickListener);
        screenOn.setOnClickListener(onClickListener);
        screenOff.setOnClickListener(onClickListener);
        memery5.setOnClickListener(onClickListener);
        memery85.setOnClickListener(onClickListener);
        protected5.setOnClickListener(onClickListener);
        protected10.setOnClickListener(onClickListener);
        refresh.setOnClickListener(onClickListener);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int width = MeasureSpec.getSize(widthMeasureSpec);
        int height = MeasureSpec.getSize(heightMeasureSpec);
        if (width > 0 && height > 0) {
            beforeMeasure();
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    private void beforeMeasure() {
        mobileChargingScrollView.getLayoutParams().height = LayoutData.getInstance().getScrollViewHeight();
        LayoutParams layoutParams = (LayoutParams) topFadeView.getLayoutParams();
        layoutParams.bottomMargin = LayoutData.getInstance().getTopFadeViewMarginBottom();
    }

    public void onReceiver(Intent intent) {
        String act = intent.getAction();
        if (Intent.ACTION_BATTERY_CHANGED.equals(act)) {
            if (!TEST) {
                updateChargingStatus(intent);
            }
        } else if (Intent.ACTION_POWER_DISCONNECTED.equals(act)) {
            MobileChargingHelper.getCharge(mContext, charge);
            if (charge.getChargingValue() == 1) {
                charge.setChargingValueType(ChargingValueType.TrickleComplete);
            }
            checkAndShowEndCard();
            MobileChargingHelper.getInstance().getColorHelper()
                    .change(MobileChargingActivity.EXTRA_FROM_DISCONNECT, hasStop);

        } else if (Intent.ACTION_POWER_CONNECTED.equals(act)) {
            charge.setFull(false);
            MobileChargingHelper.getCharge(mContext, charge);
            MobileChargingHelper.getInstance().getColorHelper()
                    .change(MobileChargingActivity.EXTRA_FROM_CONNECT, hasStop);
        } else if (Intent.ACTION_SCREEN_OFF.equals(act)) {
            onScreenOff();
        } else if (Intent.ACTION_SCREEN_ON.equals(act)) {
            onScreenOn();
        }
    }

    private void checkAndShowEndCard() {
        if (availTimeView == null) {
            availTimeView = new AvailableTimeView(getContext());
            availTimeView.initData(charge);
            addCardView(availTimeView, CardType.UseTime);
            mFadeView.setVisibility(View.VISIBLE);
        } else if (availTimeView != null) {
            availTimeView.initData(charge);
            if (availTimeView.getParent() == null) {
                addCardView(availTimeView, CardType.UseTime);
            }
        }
    }

    public void onNewIntent(boolean isScreenOn, int from) {
        isReportShowHead = true;
        theFirstShowCharge = MobileChargingHelper.getInstance().isFirstEntCharge();
        if (DEBUG) {
            Log.d(TAG, "界面从后台唤醒onNewIntent");
        }
        if (hasStop) {
            if (DEBUG) {
                Log.d(TAG, "界面被隐藏过，把现有的卡片清除");
            }
            disappearCard(true);
            hasStop = false;
        } else {
            if (DEBUG) {
                Log.d(TAG, "界面没被隐藏");
            }
        }
        if (isScreenOn) {
            dispatchShowView();
        } else {
            checkRequestAdCardData();
        }
        reportShow(from);
    }

    private void reportShow(int from) {
        String type = charge.getChargingType() == ChargingType.AC ? "0" : "1";
        String net = NetworkUtils.isNetworkAvailable(mContext) ? "0" : "1";
        Statistician2.dbLog(StatKey.STATISTIC_MOBILE_CHARGING_SHOW_ACTIVITY, type, net, from);
    }

    public void onActivityCreate(boolean screenOn, int form) {
        activityStatus = ActivityStatus.Create;
        isReportShowHead = true;
        if (DEBUG) {

            Log.d(TAG, "onActivityCreate screenOn" + screenOn);
        }
        theFirstShowCharge = MobileChargingHelper.getInstance().isFirstEntCharge();
        setChargingViews();
        if (screenOn) {
            dispatchShowView();
        } else {
            checkRequestAdCardData();
        }
        reportShow(form);
    }

    public void onScreenOn() {
        if (DEBUG) {
            Log.d(TAG, "screenOn activityStatus=" + activityStatus);
        }
        MobileChargingHelper.getInstance().getColorHelper().change(MobileChargingActivity.EXTRA_FROM_SCREENON, hasStop);
        boolean hasCard = mobileChargingScrollView.hasCard();
        if (hasCard) {
            checkRequestAdCardData();
            checkExcuteBoostAnim();
        } else {
            dispatchShowView();
        }
    }

    public void onScreenOff() {
        MobileChargingHelper.getInstance().getColorHelper()
                .change(MobileChargingActivity.EXTRA_FROM_SCREENOFF, hasStop);
        if (DEBUG) {
            Log.i(TAG, "onScreenOff==");
        }
    }

    public void onActivityResume() {
        activityStatus = ActivityStatus.Resume;
        if (DEBUG) {
            Log.d(TAG, "onActivityResume");
        }
        if (DEBUG) {
            Log.d(TAG, "界面被创建");
        }
    }

    public void onActivityStop() {
        if (DEBUG) {
            Log.d(TAG, "onActivityStop");
        }
        activityStatus = ActivityStatus.Stop;
        hasStop = true;
        mobileChargingBGView.onStop();
        mBubbleView.onStop();

    }

    public void onActivityDestory() {
        if (DEBUG) {
            Log.i(TAG, "MobileChargingView==onActivityDestory");
        }
        activityStatus = ActivityStatus.Destory;
        if (boosterView != null) {
            boosterView.onDesotry();
        }
        if (mColorHelper != null) {
            mColorHelper.destroy();
        }
        report.clear();
        MobileChargingHelper.getInstance().onChargingDestory();
    }

    public void onActivityStart() {
        if (DEBUG) {
            Log.d(TAG, "onActivityStart");
        }
        activityStatus = ActivityStatus.Start;
        mobileChargingBGView.onStart();
        mBubbleView.onStart();
    }

    private void dispatchShowView() {
        MobileChargingHelper.getInstance().refreshChage();
        if (DEBUG) {
            Log.d(TAG, "dispatchShowView");
        }
        if (boosterView != null) {
            boosterView.setVisibility(View.GONE);
        }
        if (mobileChargingScrollView != null) {
            mobileChargingScrollView.removeAllCardView();
        }

        if (theFirstShowCharge) {
            showMobileChargeTipCard();

            runable = new Runnable() {

                @Override
                public void run() {
                    mobileChargingBGView.autoShowPopWindow();
                }
            };
            mHandler.postDelayed(runable, 2000);
        }
        requestAdvGroup();

        if (!charge.isCharging()) {
            checkAndShowEndCard();
            if (DEBUG) {
                Log.d(TAG, "充电结束界面显示成功");
            }
        }
        checkExcuteBoostAnim();
    }

    private void showMobileChargeTipCard() {
        ChargingTipsCard tipCard = new ChargingTipsCard(mContext, charge);
        addCardView(tipCard, CardType.ChargeTip);
    }

    /**
     * 是否满足变色加速动画执行条件：
     * 2016/1/12 已修改，由于所有进入屏保页的场景都已经判断要设置哪种theme,为避免逻辑冲突，
     * 第一次加速动画，v5文件下发为2，这两个条件要去。最初加速动画执行条件：10分钟保护期且内存85%的条件也去掉。
     */
    private boolean isTheAnimOfBoostMeet() {
        boosterListPkg = mLockScreenBooster.getBoosterList();
        boolean needExcuDisBoost = MobileChargingHelper.getInstance().getColorHelper().needDiscolorationBoost();
        if (DEBUG) {
            Log.i(TAG, "needExcuDisBoost==" + needExcuDisBoost);
        }
        if (needExcuDisBoost) {
            return true;
        }
        return false;
    }

    private void checkExcuteBoostAnim() {
        boolean isCharging = charge.isCharging();
        mColorHelper.setBoosting(false);
        if (isCharging) {
            if (DEBUG) {
                Log.d(TAG, "正在充电，判断是否需要加速");
            }
            //fix bug:针对有些手机锁屏时广播慢导致的bug,插上电源满足条件执行加速动画后，瞬间锁屏亮屏还会执行加速动画，加上保护期判断
            boolean isProtectionPreriod = mLockScreenBooster.isBoostProtectionPeriod();
            if (DEBUG) {
                Log.i(TAG, "isProtectionPreriod==" + isProtectionPreriod);
            }
            if (isTheAnimOfBoostMeet() && isProtectionPreriod) {
                if (boosterListPkg == null || boosterListPkg.isEmpty()) {
                    if (DEBUG) {
                        Log.i(TAG, "boosterListPkg==数据为空");
                    }
                    return;
                }
                if (mColorHelper != null) {
                    mColorHelper.setChargeColorData();//满足加速动画条件且当前获取到了加速数据，设置颜色进行变色加速动画。
                }
                if (DEBUG) {
                    Log.i(TAG, "boosterListPkg==" + boosterListPkg.toString());
                }
                if (boosterView == null) {
                    ViewStub viewStub = (ViewStub) findViewById(R.id.magic_layout_viewstub);
                    if (viewStub != null) {
                        boosterView = (MagicLayout) viewStub.inflate();
                        boosterView.setOnClickListener(this);
                    }
                }
                if (boosterView == null) {
                    return;
                }
                mColorHelper.setBoosting(true);
                boosterView.setPkgList(boosterListPkg);
                boosterView.setVisibility(View.VISIBLE);
                ViewHelper.setAlpha(boosterView, 1.0f);
                mColorHelper.startDiscoloration();
                if (objectAnimator != null && objectAnimator.isRunning()) {
                    objectAnimator.cancel();
                }
                objectAnimator = ObjectAnimator.ofFloat(boosterView, "alpha", 1, 0);
                objectAnimator.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        displayBoostResultCard();
                        boosterView.setVisibility(View.GONE);
                        boosterView.onDesotry();
                        mLockScreenBooster.oneKeyBoost();
                        mFadeView.setVisibility(View.VISIBLE);
                        mLockScreenBooster.setBoostProtectionPeriod();
                        setAlphaAnim();
                        mColorHelper.setBoosting(false);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        super.onAnimationCancel(animation);
                        boosterView.onDesotry();
                        mLockScreenBooster.oneKeyBoost();
                        mColorHelper.setBoosting(false);
                    }

                    @Override
                    public void onAnimationStart(Animator animation) {
                        super.onAnimationStart(animation);

                    }

                });
                objectAnimator.setDuration(1000);
                objectAnimator.setStartDelay(3000);
                removeCallBack();
                mobileChargingBGView.removePop();
                mobileChargingBGView.getChargingProgress().setProgressAlpha(0);
                mobileChargingScrollView.setChildViewAlpha(0);
                objectAnimator.start();
                if (DEBUG) {
                    Log.d(TAG, "正在执行加速动画");
                }
                Statistician2.dbLog(StatKey.STATISTIC_MOBILE_CHARGING_BOOSTER_ANI, Utils.getMemoryUsedPercent());
            }
        }
    }

    public void removeCallBack() {
        if (mHandler != null && runable != null) {
            mHandler.removeCallbacks(runable);
        }
    }

    private void requestAdvGroup() {
        mLockScreenAd.requestAdvGroup();
        //        if (AppUtils.noAdData(mContext)) {
        //            if (DEBUG) {
        //                Log.d(TAG, "低配手机，不发广告请求");
        //            }
        //        } else {
        //            if (DEBUG) {
        //                Log.d(TAG, "begin-请求广告（不一定发网络请求，先看本地缓存有没有过期）");
        //            }
        //            fbIds.clear();
        //            AdvDataHelper.getInstance().beginRequestAdvGroup(AdvTypeConfig.MobileChargingAdvData);
        //            if (DEBUG) {
        //                Log.d(TAG, "-end(如果此log没有紧跟begin-之后，说明用的是缓存数据)");
        //            }
        //        }
    }

    private void setAlphaAnim() {
        ValueAnimator valueAnimator = ValueAnimator.ofFloat(0f, 1f);
        valueAnimator.setInterpolator(new LinearInterpolator());
        valueAnimator.addUpdateListener(new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float alpha = (Float) valueAnimator.getAnimatedValue();
                mobileChargingBGView.getChargingProgress().setProgressAlpha(alpha);
                mobileChargingScrollView.setChildViewAlpha(alpha);
            }
        });
        valueAnimator.setDuration(600);
        valueAnimator.start();
    }

    private void addCardView(View v, CardType cardType) {
        addCardView(v, cardType, createDefaultLayoutParams());
    }

    private LinearLayout.LayoutParams createDefaultLayoutParams() {
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        return layoutParams;
    }

    private void addCardView(View v, CardType cardType, LinearLayout.LayoutParams params) {
        if (v == null || cardType == CardType.Null) {
            mobileChargingScrollView.removeAllCardView();
            return;
        }
        if (DEBUG) {
            Log.d(TAG, "设置显示卡片:" + cardType);
        }
        if (v != null) {
            v.setTag(cardType);
            ViewHelper.setTranslationX(v, 0);
            mobileChargingScrollView.addCardViews(v, cardType, params);
        }
        reportIfAdInMultiCardsShow();
    }

    private void reportIfAdInMultiCardsShow() {
        boolean is = mobileChargingScrollView.isAdInMultipleCards();
        if (is) {
            Statistician2.dbLog(StatKey.STATISTIC_MOBILE_CHARGING_AD_INMULTIPLE_CARDS, 0);
        }
    }

    private void reportIfAdInMultiCardsClick() {
        boolean is = mobileChargingScrollView.isAdInMultipleCards();
        if (is) {
            Statistician2.dbLog(StatKey.STATISTIC_MOBILE_CHARGING_AD_INMULTIPLE_CARDS, 1);
        }
    }

    private void replaceCardView(View v, CardType cardType) {
        if (v == null || cardType == CardType.Null) {
            mobileChargingScrollView.removeAllCardView();
            return;
        }
        if (DEBUG) {
            Log.d(TAG, "设置显示卡片:" + cardType);
        }
        if (v != null) {
            v.setTag(cardType);
            ViewHelper.setTranslationX(v, 0);
            mobileChargingScrollView.replaceCardView(v, cardType, createDefaultLayoutParams());

        }
        reportIfAdInMultiCardsShow();
    }

    /**
     * 显示加速结果卡片
     */
    private void displayBoostResultCard() {
        List<String> dataList = mLockScreenBooster.getPowerConsumptionList();
        if (dataList != null && !dataList.isEmpty()) {
            if (boostResultView == null) {
                boostResultView = new BoostResultCardView(getContext(), dataList);
                addCardView(boostResultView, CardType.BoosterResult);
            } else if (boostResultView != null) {
                if (boostResultView.getParent() == null) {
                    addCardView(boostResultView, CardType.BoosterResult);
                }
            }
        }
    }

    //    public void onEventMainThread(AdvEvent event) {
    //        if (event.advType == null || event.advSpaces == null) {
    //            return;
    //        }
    //        if (DEBUG) {
    //            Log.i(TAG, "AdvEvent mid = " + event.advType.getMid());
    //        }
    //        switch (event.advType.getMid()) {
    //        case AdvTypeConfig.MID_CHARGE:
    //            List<AdvData> advDatas = new ArrayList<AdvData>();
    //            AdvDataHelper.getTimerAdvData(event.advType, advDatas, event.advSpaces);
    //            if (DEBUG) {
    //                Log.d(TAG, "直客广告数量为" + advDatas.size());
    //            }
    //            if (advDatas.size() > 0) {
    //                removeCallBack();
    //                mobileChargingBGView.removePop();
    //                setAdvView(advDatas);
    //            }
    //            break;
    //        default:
    //            break;
    //        }
    //    }

    //    private void setAdvView(List<AdvData> advDatas) {
    //        if (DEBUG) {
    //            Log.d(TAG, "准备显示广告 setAdvView()");
    //        }

    //        if (advDatas.size() > 0) {
    //            AdvData advData = advDatas.get(0);
    //            if (advData != null) {
    //                if (DEBUG) {
    //                    boolean isfb = advData.nativeAd != null;
    //                    Log.d(TAG, "sid=" + advData.sid + "被展示广告的标题为:" + advData.title + "\n小图片地址" + advData.icon
    //                            + "\n大图片地址:" + advData.creatives + " \n是否为fb广告" + isfb);
    //                }
    //
    //                View v = bindAdView(advData);
    //                if (v == null) {
    //                    if (DEBUG) {
    //                        Log.d(TAG, "setAdvView. ad view=null");
    //                    }
    //                    return;
    //                }
    //                v.setTag(R.id.root, advData);
    //                needReportShowAdvData = advData;
    //                if (adCardHeight != 0) {
    //                    LinearLayout.LayoutParams layoutParams = createDefaultLayoutParams();
    //                    layoutParams.height = (int) adCardHeight;
    //                    if (DEBUG) {
    //                        Log.i(TAG, "adCardHeight==" + adCardHeight);
    //                    }
    //                } else {
    //                    if (DEBUG) {
    //                        Log.i(TAG, "adCardHeight为0");
    //                    }
    //                }
    //
    //                mFadeView.setVisibility(View.VISIBLE);
    //                if (mobileChargingScrollView.hasAdCard()) {
    //                    if (DEBUG) {
    //                        Log.i(TAG, "hasAdCard == true");
    //                    }
    //                    AdvData find = mobileChargingScrollView.findAdvData();
    //                    if (find != null) {
    //                        Statistician2.dbLog(StatKey.STATISTIC_MOBILE_CHARGING_AD_REPLACED, find.adid, advData.adid);
    //                    }
    //                    replaceCardView(v, CardType.AD);
    //                } else {
    //                    if (DEBUG) {
    //                        Log.i(TAG, "hasAdCard == false");
    //                    }
    //                    addCardView(v, CardType.AD);
    //                }
    //                Statistician2.dbLog(StatKey.STATISTIC_MOBILE_CHARGING_AD_SHOW,
    //                        NetworkUtils.getNetWorkType(getContext()));
    //            } else {
    //                if (DEBUG) {
    //                    Log.d(TAG, "展示的广告为空");
    //                }
    //            }
    //        } else {
    //            if (DEBUG) {
    //                Log.d(TAG, "要展示的广告数据为0,所以不展示广告");
    //            }
    //        }
    //    }

    //    private View bindAdView(AdvData advData) {

    View v = null;

    //        if (advData.sid == AdvEnv.ADV_SID_GOOGLE) {
    //            if (advData != null && advData.googleAd != null && advData.googleAd.nativeAd != null) {
    //                if (advData.googleAd.nativeAd instanceof NativeContentAd) {
    //                    if (DEBUG) {
    //                        Log.d(TAG, "bindAdView.NativeContentAd");
    //                    }
    //                    NativeContentAd ad = (NativeContentAd) advData.googleAd.nativeAd;
    //                    v = layoutInflater.inflate(R.layout.mobile_charging_google_content_ad_view, null);
    //                    View clickMask = v.findViewById(R.id.material_view);
    //                    clickMask.setOnClickListener(this);
    //                    clickMask.setTag(advData);
    //                    TextView contentadHeadline;
    //                    TextView downloadBtn;
    //                    ImageView contentadLogo;
    //                    contentadHeadline = (TextView) v.findViewById(R.id.contentad_headline);
    //                    contentadLogo = (ImageView) v.findViewById(R.id.contentad_logo);
    //                    downloadBtn = (TextView) v.findViewById(R.id.download_btn);
    //                    clickMask.setTag(R.id.material_view, downloadBtn);
    //                    AssertRemoteImageView contentadIcon = (AssertRemoteImageView) v.findViewById(R.id.contentad_icon);
    //                    contentadIcon.setVisibility(View.GONE);
    //                    setText(contentadHeadline, ad.getHeadline());
    //                    setText(downloadBtn, ad.getCallToAction());
    //                    final NativeContentAdView adView = (NativeContentAdView) v.findViewById(R.id.root);
    //                    adView.setHeadlineView(contentadHeadline);
    //                    adView.setCallToActionView(downloadBtn);
    //                    adView.setImageView(contentadLogo);
    //                    if (adView != null) {
    //                        String url = AdvDataHelper.getGoolgeNativeAdUrl(advData);
    //                        setImageURL(contentadLogo, url);
    //                    } else {
    //                        if (DEBUG) {
    //                            Log.i(TAG, "bindAdView drawable null");
    //                        }
    //                    }
    //                    adView.setNativeAd(ad);
    //                } else {
    //                    if (DEBUG) {
    //                        Log.d(TAG, "bindAdView.NativeAppInstallAd");
    //                    }
    //                    NativeAppInstallAd ad = (NativeAppInstallAd) advData.googleAd.nativeAd;
    //                    v = layoutInflater.inflate(R.layout.mobile_charging_google_install_ad_view, null);
    //                    View clickMask = v.findViewById(R.id.material_view);
    //                    clickMask.setTag(advData);
    //                    clickMask.setOnClickListener(this);
    //                    TextView contentadHeadline;
    //                    TextView downloadBtn;
    //                    ImageView contentadLogo;
    //                    contentadHeadline = (TextView) v.findViewById(R.id.contentad_headline);
    //                    contentadLogo = (ImageView) v.findViewById(R.id.contentad_logo);
    //                    downloadBtn = (TextView) v.findViewById(R.id.download_btn);
    //                    clickMask.setTag(R.id.material_view, downloadBtn);
    //                    AssertRemoteImageView contentadIcon = (AssertRemoteImageView) v.findViewById(R.id.contentad_icon);
    //                    setText(contentadHeadline, ad.getHeadline());
    //                    setText(downloadBtn, ad.getCallToAction());
    //                    NativeAppInstallAdView adView = (NativeAppInstallAdView) v.findViewById(R.id.root);
    //                    adView.setHeadlineView(contentadHeadline);
    //                    adView.setCallToActionView(downloadBtn);
    //                    adView.setImageView(contentadLogo);
    //                    if (contentadIcon != null && ad.getIcon() != null && ad.getIcon().getUri() != null) {
    //                        setImageURL(contentadIcon, ad.getIcon().getUri().toString());
    //                    }
    //                    if (adView != null) {
    //                        String url = AdvDataHelper.getGoolgeNativeAdUrl(advData);
    //                        setImageURL(contentadLogo, url);
    //                    } else {
    //                        if (DEBUG) {
    //                            Log.i(TAG, "bindAdView drawable null");
    //                        }
    //                    }
    //                    adView.setNativeAd(ad);
    //                }
    //            } else {
    //                if (DEBUG) {
    //                    Log.d(TAG, "bindAdView.google ad=null");
    //                }
    //                return null;
    //            }
    //        } else {
    //
    //            //应该在AdvEnv中做常量配置，暂时hardcode 14
    //            if (advData.tp == 14) {
    //                v = layoutInflater.inflate(R.layout.mobile_charging_ad_view_tp14, null);
    //            } else {
    //                v = layoutInflater.inflate(R.layout.mobile_charging_ad_view, null);
    //            }
    //
    //            RemoteImageView icon = (RemoteImageView) v.findViewById(R.id.icon);
    //            RemoteImageView img = (RemoteImageView) v.findViewById(R.id.img);
    //
    //            //如果tp类型是14，则title和操作按钮横条位于图片下方
    //            if (advData.tp == 14) {
    //                int imgWidth = ScreenUtil.getScreenWidth(mContext) - LayoutData.getInstance().getCardMarginLeft() * 2;
    //                int imgHeight = (int) (imgWidth / img.getRatio());
    //                LinearLayout adOperateLayout = (LinearLayout) v.findViewById(R.id.ad_operate_layout);
    //                ((FrameLayout.LayoutParams) adOperateLayout.getLayoutParams()).setMargins(0, imgHeight, 0, 0);
    //            }
    //
    //            TextView title = (TextView) v.findViewById(R.id.des);
    //            TextView btnName = (TextView) v.findViewById(R.id.btn_name);
    //            View clickmaster = v.findViewById(R.id.facebook_click_master);
    //            View materialView = v.findViewById(R.id.material_view);
    //            title.setText(advData.title);
    //            if (!TextUtils.isEmpty(advData.btnName)) {
    //                btnName.setText(advData.btnName);
    //            } else {
    //                btnName.setText(LockScreenSDK.getInstance().getString(R.string.app_box_app_is_not_installed));
    //            }
    //            icon.setImageURL(advData.icon, R.drawable.game_booster_icon_default);
    //            img.setImageURL(advData.creatives, R.drawable.game_booster_icon_default);
    //            materialView.setOnClickListener(this);
    //            materialView.setTag(advData);
    //            //            去掉flurry的相關代碼
    //            /* if (advData.sid == AdvEnv.ADV_SID_FLURRY) {
    //                 materialView.setVisibility(View.GONE);
    //                 materialView.setClickable(false);
    //                 registFlurry(advData, v, title, img, icon);
    //             }*/
    //            if (advData.sid == AdvEnv.ADV_SID_VK && advData.vkAd != null && advData.vkAd.nativeAd != null) {
    //                advData.vkAd.nativeAd.registerView(clickmaster);
    //                registedVKNativeAd.add(advData.vkAd.nativeAd);
    //            } else if (advData.sid == AdvEnv.ADV_SID_FACEBOOK && advData.nativeAd != null) {
    //                advData.nativeAd.registerViewForInteraction(clickmaster);
    //                registedNativeAd.add(advData.nativeAd);
    //            }
    //        }
    //        return v;
    //    }

    private void setImageURL(ImageView imageView, String url) {
        //        if (!TextUtils.isEmpty(url) && imageView != null) {
        //            ((RemoteImageView) imageView).setImageURL(url, 0);
        //            if (DEBUG) {
        //                Log.d(TAG, "setImageURL. imgUrl=" + url);
        //            }
        //        } else if (imageView != null) {
        //            imageView.setImageResource(R.drawable.game_booster_icon_default);
        //        }
    }

    private void setText(TextView textview, CharSequence str) {
        if (textview == null) {
            return;
        }
        if (TextUtils.isEmpty(str)) {
            textview.setText("");
        } else {
            textview.setText(str);
        }
    }

    //去掉flurry广告的相关代码
    /*private void registFlurry(AdvData data, View rootView, View titleView, View bigImage, View iconView) {
        data.fNativeAd.nativeAd.getAsset("headline").loadAssetIntoView(titleView);
        //        data.fNativeAd.getAsset("summary").loadAssetIntoView(
        //                advCardView.mCardDescription);
        data.fNativeAd.nativeAd.getAsset("secHqBrandingLogo").loadAssetIntoView(iconView);
        data.fNativeAd.nativeAd.getAsset("secHqImage").loadAssetIntoView(bigImage);
        //            FlurryAdNativeAsset appCategoryAsset = data.fNativeAd.nativeAd.getAsset("appCategory");
        //            if (appCategoryAsset != null) {
        //                appCategoryAsset.loadAssetIntoView(
        //                        advCardView.mDownloadBtn);
        //            }
        data.fNativeAd.nativeAd.setTrackingView(rootView);
    }*/

    private void updateChargingStatus(Intent intent) {
        MobileChargingHelper.getCharge(intent, charge);
        setChargingViews();
    }

    public void disappearCard(boolean remove) {
        if (remove) {
            addCardView(null, CardType.Null);
            mColorHelper.setBoosting(false);
        }
        mFadeView.setVisibility(View.INVISIBLE);
    }

    private void setChargingViews() {
        mobileChargingBGView.setCharge(charge);
        mBubbleView.setCharge(charge);
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (MobileChargingHelper.getInstance().getClickTask() == null) {
            unregistAds();
        }
        mColorHelper.deleteObserver(mobileChargingBGView);
        mColorHelper.deleteObserver(mFadeView);
        mColorHelper.deleteObserver(slideTextView);
        removeCallBack();
        if (mColorHelper != null) {
            mColorHelper.setColorThemeBlue();
            mColorHelper.setChargeColorData();
        }
    }

    private void unregistAds() {
        //        for (NativeAd nativeAd : registedNativeAd) {
        //            nativeAd.unregisterView();
        //        }
        //        registedNativeAd.clear();
        //        for (NativePromoAd vkAd : registedVKNativeAd) {
        //            vkAd.unregisterView();
        //        }
        //        registedVKNativeAd.clear();
    }

    private void checkRequestAdCardData() {
        boolean hasAdCard = mobileChargingScrollView.hasAdCard();
        if (DEBUG) {
            Log.i(TAG, "hasAdCard==" + hasAdCard);
        }
        if (hasAdCard) {
            boolean overdue = mLockScreenAd.isOverDue();
            if (DEBUG) {
                Log.i(TAG, "isoverdue==" + overdue);
            }
            if (overdue) {
                if (DEBUG) {
                    Log.i(TAG, "有广告卡片，但是广告已经过期直接请求广告");
                }
                mLockScreenAd.requestAdvGroup();
            } else {
                if (DEBUG) {
                    Log.i(TAG, "广告没有过期，不做任何处理");
                }
            }
        } else {
            if (DEBUG) {
                Log.i(TAG, "有卡片但是没有广告卡片直接请求广告数据");
            }
            mLockScreenAd.requestAdvGroup();
        }
    }

    //    private void clickAdv(View v) {
    //        Object tag = v.getTag();
    //        AdvData advData = (AdvData) tag;
    //        if (advData.sid == AdvEnv.ADV_SID_FLURRY) {
    //            return;
    //        }
    //        clickAdv(v, advData);
    //        AdvUtils.doAdvClickDblog(AdvTypeConfig.MobileChargingAdvData, advData.pid, advData.sid);
    //        List<AdvData> list = new ArrayList<AdvData>();
    //        list.add(advData);
    //        AdvReportHelper.reportAdvClick(mContext, list);
    //        reportIfAdInMultiCardsClick();
    //    }

    @Override
    public void onClick(final View v) {
        switch (v.getId()) {
        case R.id.material_view:
            //            if (ScreenUtil.isSreenLocked(mContext)) {
            //                Runnable run = new Runnable() {
            //                    @Override
            //                    public void run() {
            //                        clickAdv(v);
            //                        mActivity.finish();
            //
            //                    }
            //                };
            //                MobileChargingHelper.getInstance().setClickTask(run);
            //                mActivity.moveTaskToBack(true);
            //            } else {
            //                MobileChargingHelper.getInstance().setClickTask(null);
            //                clickAdv(v);
            //
            //                //                        为了让打开广告后消失的更快改用moveTaskToBack
            //                mHandler.postDelayed(new Runnable() {
            //                    @Override
            //                    public void run() {
            //
            //                        mActivity.finish();
            //                    }
            //                }, 1000);
            //
            //            }
            //            MobileChargingHelper.getInstance().removeScreenOnMeesage();

            break;

        case R.id.switch_menu:
            initPopupWindow(v);
            break;
        case R.id.disable_button:
            if (popupWindow.isShowing()) {
                popupWindow.dismiss();
            }
            initDialog(v.getContext());
            break;
        default:
            break;
        }
    }

    private void initDialog(Context context) {
        //        final boolean isOpen = MobileChargingHelper.getInstance().isOpenFastChargeFunc();
        //        final SimpleDialog dialog = new SimpleDialog(context, isOpen ? R.string.disable_speed_charge_title
        //                : R.string.enable_speed_charge_title, isOpen ? R.string.disable_speed_charge_msg
        //                : R.string.enable_speed_charge_msg);
        //        if (isOpen) {
        //            dialog.setButtonText(R.string.not_now, R.string.disable);
        //            dialog.setButtonOnClickListener(new OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    DialogUtils.dismissDialog(dialog);
        //                }
        //            }, new OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    MobileChargingHelper.getInstance().setOpenFastChargeFunc(!isOpen);
        //                    MobileChargingHelper.getInstance().setUserCloseFastChargeFunc(true);
        //                    //关是1
        //                    Statistician2.dbLog(StatKey.STATISTIC_MOBILE_CHARGING_MENU_CLOSE_CLICK, 0);
        //                    EventBus.getDefault().post(ChargingEvent.CHARGING_DISABLE);
        //                    DialogUtils.dismissDialog(dialog);
        //                }
        //            });
        //        } else {
        //            dialog.setButtonText(R.string.appmgr_enable, R.string.cancel);
        //            dialog.setButtonOnClickListener(new OnClickListener() {
        //
        //                @Override
        //                public void onClick(View v) {
        //                    MobileChargingHelper.getInstance().setOpenFastChargeFunc(!isOpen);
        //                    //关是1
        //                    Statistician2.dbLog(StatKey.STATISTIC_MOBILE_CHARGING_MENU_CLOSE_CLICK, 1);
        //                    EventBus.getDefault().post(ChargingEvent.CHARGING_DISABLE);
        //                    DialogUtils.dismissDialog(dialog);
        //                }
        //            }, new OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    DialogUtils.dismissDialog(dialog);
        //                }
        //            });
        //        }
        //        dialog.setCancelable(true);
        //        DialogUtils.showDialog(dialog);

    }

    private void initPopupWindow(View view) {
        LinearLayout layout = (LinearLayout) layoutInflater.inflate(R.layout.speed_charge_switch_popupwindow, null);
        TextView switchMenu = (TextView) layout.findViewById(R.id.disable_button);
        boolean isOpen = MobileChargingHelper.getInstance().isOpenFastChargeFunc();
        int resId = isOpen ? R.string.disable : R.string.appmgr_enable;
        switchMenu.setText(resId);
        switchMenu.setOnClickListener(this);
        popupWindow = new PopupWindow(layout, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        popupWindow.setFocusable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setOutsideTouchable(true);
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        int x = location[0] - AppUtils.dip2px(mContext, 48);
        int y = location[1] + AppUtils.dip2px(mContext, 56);
        popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, x, y);
        Statistician2.dbLog(StatKey.STATISTIC_MOBILE_CHARGING_MENU_CLICK);
    }

    //    private void clickAdv(View v, AdvData advData) {
    //        switch (advData.sid) {
    //        case AdvEnv.ADV_SID_APPLOVIN:
    //            AdvDataHelper.openAdv(advData);
    //            break;
    //        case AdvEnv.ADV_SID_FACEBOOK:
    //        case AdvEnv.ADV_SID_VK:
    //            View parent = (View) v.getParent();
    //            View clickMaster = parent.findViewById(R.id.facebook_click_master);
    //            if (clickMaster != null) {
    //                clickMaster.performClick();
    //            }
    //            break;
    //        case AdvEnv.ADV_SID_GOOGLE:
    //            Object o = v.getTag(R.id.material_view);
    //            if (o instanceof View) {
    //                View btn = (View) o;
    //                btn.performClick();
    //            }
    //            break;
    //        default:
    //            AdvDataHelper.openAdv(advData);
    //            break;
    //        }
    //    }

    @Override
    public void onScroll(ScrollInfo scrollInfo) {
        mobileChargingBGView.getChargingProgress().onScroll(scrollInfo);
        mobileChargingBGView.onScroll(scrollInfo);
        mFadeView.onScroll(scrollInfo);
        topFadeView.onScroll(scrollInfo);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            //down事件不是抢来的，而是事件没任何view接收的时候，自己就接下这个事件，后续事件才会传过来.
            //（4.0即便不返回true后续也能走onInterceptTouchEvent->再走onTouch，但是2.2，如果不返回true,是拿 不到后续事件）.
            startX = event.getRawX();
            startY = event.getRawY();
            isSlidAnimating = false;
            return true;
        case MotionEvent.ACTION_MOVE:
            if (isSlidAnimating) {
                return false;
            }
            offsetX = event.getRawX() - startX;
            if (offsetX > 0) {
                ViewHelper.setTranslationX(this, offsetX);
            }
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            startX = 0;
            float currentTranslateX = ViewHelper.getTranslationX(this);
            if (offsetX < getMeasuredWidth() * 0.4f) {
                animatSlid(false, currentTranslateX, 0);
            } else {
                animatSlid(true, currentTranslateX, getMeasuredWidth());
            }
            break;
        default:
            break;
        }
        return super.onTouchEvent(event);
    }

    private void animatSlid(final boolean isFinish, float fromTranslate, float targetTranslate) {
        isSlidAnimating = true;
        float duration = (targetTranslate - fromTranslate) / LayoutData.getInstance().getDensity();
        //        float duration = (targetTranslate - fromTranslate) / LayoutData.getInstance().getDensity();
        ValueAnimator valueAnimator = ValueAnimator.ofFloat(fromTranslate, targetTranslate);
        valueAnimator.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float tx = (Float) valueAnimator.getAnimatedValue();
                ViewHelper.setTranslationX(MobileChargingView.this, tx);

            }
        });
        valueAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                if (isFinish && slideListener != null) {
                    slideListener.OnChargingViewSlideFinished();
                }
                isSlidAnimating = false;
            }
        });
        valueAnimator.setInterpolator(new AccelerateInterpolator());
        valueAnimator.setDuration(200);
        valueAnimator.start();

    }

    public void setOnChargingViewSlideListener(OnChargingViewSlideListener listener) {
        this.slideListener = listener;
    }

    public interface OnChargingViewSlideListener {
        public void OnChargingViewSlideFinished();
    }

    @Override
    public void onRemove(View v, CardType cardType) {
        if (DEBUG) {
            Log.d(TAG, "onRemove CardType=" + cardType);
        }
        if (cardType == null) {
            return;
        }
        int type = 1;
        if (cardType == CardType.BoosterResult) {
            type = 2;
        } else if (cardType == CardType.UseTime) {
            type = 3;
        } else {
            type = 0;
        }
        Statistician2.dbLog(StatKey.STATISTIC_MOBILE_CHARGING_DELETE_CARD, type);
    }

    @Override
    public void onCardShowAll(View v, CardType cardType) {

        if (DEBUG) {
            Log.d(TAG, "onCardShowAll CardType=" + cardType);
        }
        //        if (cardType == null) {
        //            return;
        //        }
        //        if (needReportShowAdvData != null) {
        //            ArrayList<AdvData> advDatas = new ArrayList<AdvData>();
        //            advDatas.add(needReportShowAdvData);
        //            AdvUtils.doAdvShowDblog(AdvTypeConfig.MobileChargingAdvData, advDatas);
        //            AdvReportHelper.reportAdvShow(mContext, advDatas);
        //            needReportShowAdvData = null;
        //        }
        //        if (report.contains(cardType.showAll)) {
        //            return;
        //        }
        //        if (cardType == CardType.UseTime) {
        //            Statistician2.dbLog(cardType.showAll, NetworkUtils.getNetWorkType(getContext()));
        //        } else {
        //            Statistician2.dbLog(cardType.showAll);
        //        }
        //        report.add(cardType.showAll);
    }

    @Override
    public void onCardShowHead(View v, CardType cardType) {
        if (DEBUG) {
            Log.d(TAG, "onCardShowHead CardType=" + cardType);
        }
        if (cardType == null) {
            return;
        }
        if (isReportShowHead && activityStatus == ActivityStatus.Resume) {//现在改为每次onNewIntent也会上报
            int showHead = cardType.showHead;
            if (showHead > 0) {
                Statistician2.dbLog(cardType.showHead);
            }
            isReportShowHead = false;
        }
    }

    @Override
    public boolean canSlidDelete(View v) {
        //        Object o = v.getTag(R.id.root);
        //        if (o != null && o instanceof AdvData) {
        //
        //            AdvData advData = (AdvData) o;
        //            if (advData.sid == AdvEnv.ADV_SID_GOOGLE) {
        //                return false;
        //            }
        //        }
        return true;
    }

    @Override
    public boolean needShowAdAll(View v) {
        //        Object o = v.getTag(R.id.root);
        //        if (o != null && o instanceof AdvData) {
        //            AdvData advData = (AdvData) o;
        //            return advData.drag == AdvData.DRAG_SHOW_ALL;
        //        }
        return false;
    }

    @Override
    public void onOpenAd(View slidingView) {
        View materialView = slidingView.findViewById(R.id.material_view);
        if (materialView != null) {
            onClick(materialView);
            Statistician2.dbLog(StatKey.STATISTIC_MOBILE_SLID_OPEN_AD_CARD);
        }
    }
}
